<!DOCTYPE html>
<html>
<head>
    <!-- 页面meta -->
    <meta charset="utf-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <title>传智健康</title>
    <meta name="description" content="传智健康">
    <meta name="keywords" content="传智健康">
    <meta content="width=device-width,initial-scale=1,maximum-scale=1,user-scalable=no" name="viewport">
    <!-- 引入样式 -->
    <link rel="stylesheet" href="../plugins/elementui/index.css">
    <link rel="stylesheet" href="../plugins/font-awesome/css/font-awesome.min.css">
    <link rel="stylesheet" href="../css/style.css">
    <style>
        .avatar-uploader .el-upload {
            border: 1px dashed #d9d9d9;
            border-radius: 6px;
            cursor: pointer;
            position: relative;
            overflow: hidden;
        }

        .avatar-uploader .el-upload:hover {
            border-color: #409EFF;
        }

        .avatar-uploader-icon {
            font-size: 28px;
            color: #8c939d;
            width: 178px;
            height: 178px;
            line-height: 178px;
            text-align: center;
        }

        .avatar {
            width: 178px;
            height: 178px;
            display: block;
        }

        .datatable {
            position: relative;
            box-sizing: border-box;
            -webkit-box-flex: 1;
            width: 100%;
            max-width: 100%;
            font-size: 14px;
            color: rgb(96, 98, 102);
            overflow: hidden;
            flex: 1 1 0%;
        }

        .datatable td, .datatable th {
            padding: 12px 0;
            min-width: 0;
            -webkit-box-sizing: border-box;
            box-sizing: border-box;
            text-overflow: ellipsis;
            vertical-align: middle;
            position: relative;
            text-align: left;
        }
    </style>
</head>
<body class="hold-transition">
<div id="app">
    <div class="content-header">
        <h1>体检机构<small>地址管理</small></h1>
        <el-breadcrumb separator-class="el-icon-arrow-right" class="breadcrumb">
            <el-breadcrumb-item :to="{ path: '/' }">首页</el-breadcrumb-item>
            <el-breadcrumb-item>体检机构</el-breadcrumb-item>
            <el-breadcrumb-item>地址管理</el-breadcrumb-item>
        </el-breadcrumb>
    </div>
    <div class="app-container">
        <div class="box">
            <div class="filter-container">
                <el-input placeholder="体检机构名/体检机构" v-model="pagination.queryString" style="width: 200px;"
                          class="filter-item" @keyup.enter.native="handleFilter"></el-input>
                <el-button @click="findPage()" class="dalfBut">查询</el-button>
                <el-button type="primary" class="butT" @click="handleCreate()">新建</el-button>
            </div>
            <el-table size="small" current-row-key="id" :data="dataList" stripe highlight-current-row>
                <el-table-column type="index" align="center" label="序号"></el-table-column>
                <el-table-column prop="name" label="体检机构名" align="center"></el-table-column>
                <el-table-column prop="phoneNumber" label="联系电话" align="center"></el-table-column>
                <el-table-column prop="coordinate" label="经纬度" align="center"></el-table-column>
<!--                <el-table-column prop="img" label="机构图片" align="center"></el-table-column>-->
                <el-table-column prop="addressDetails" label="详细地址" align="center"></el-table-column>
                <el-table-column label="操作" align="center">
                    <template slot-scope="scope">
                        <el-button type="primary" size="mini" @click="handleUpdate(scope.row)">编辑</el-button>
                        <el-button size="mini" type="danger" @click="handleDelete(scope.row)">删除</el-button>
                    </template>
                </el-table-column>
            </el-table>
            <div class="pagination-container">
                <el-pagination
                        class="pagiantion"
                        @current-change="handleCurrentChange"
                        :current-page="pagination.currentPage"
                        :page-size="pagination.pageSize"
                        layout="total, prev, pager, next, jumper"
                        :total="pagination.total">
                </el-pagination>
            </div>
            <!-- 新增标签弹层 -->
            <div class="add-form">
                <el-dialog title="新增体检机构地址" :visible.sync="dialogFormVisible" width="80%">
                    <el-form ref="dataAddForm" :model="formData" :rules="rules" label-position="right"
                             label-width="100px">
                        <el-row>
                            <el-col :span="12">
                                <el-form-item label="体检机构名" prop="name">
                                    <el-input v-model="formData.name"/>
                                </el-form-item>
                            </el-col>
                            <el-col :span="12">
                                <el-form-item label="联系电话" prop="phoneNumber">
                                    <el-input v-model="formData.phoneNumber"/>
                                </el-form-item>
                            </el-col>
                        </el-row>
                        <el-row>
                            <el-col :span="24">
                                <el-form-item label="上传体检机构地址图片">
                                    <el-upload
                                            class="avatar-uploader"
                                            action="/address/upload.do"
                                            :auto-upload="autoUpload"
                                            name="imgFile"
                                            :show-file-list="false"
                                            :on-success="handleAvatarSuccess"
                                            :before-upload="beforeAvatarUpload">
                                        <img v-if="imageUrl" :src="imageUrl" class="avatar">
                                        <i v-else class="el-icon-plus avatar-uploader-icon"></i>
                                    </el-upload>
                                </el-form-item>
                            </el-col>
                        </el-row>
                        <el-row>
                            <el-col :span="20">
                                <el-form-item label="经纬度" prop="coordinate">
                                    <el-input v-model="formData.coordinate" id="lngAndLat" >
                                    </el-input>
                                </el-form-item>
                            </el-col>
                        </el-row>
                        <el-row>
                            <el-col :span="14">
                                <el-form-item label="详细地址">
                                    <el-input id="address" v-model="formData.addressDetails"></el-input>
                                </el-form-item>
                            </el-col>

<!--                            <el-col :span="4">-->
<!--                                &lt;!&ndash; <el-button type="primary" @click="setLocation()" round>-->
<!--                                     设置定位-->
<!--                                 </el-button>&ndash;&gt;-->
<!--                                <el-button type="primary" @click="setLocation()" icon="el-icon-location" round>位置定位-->
<!--                                </el-button>-->
<!--                            </el-col>-->

                            <el-col :span="4">
                                <el-button type="primary" icon="el-icon-location"
                                           @click="sear()">
                                    按地址搜索
                                </el-button>
                            </el-col>
                        </el-row>
<!--                        <er-row>-->
<!--                            <el-col :span="10">-->
<!--                                <input name="address" value="" id="where" class="case_text" type="text">-->
<!--                                <el-button type="primary" icon="el-icon-location" style="display: inline" @click="sear()">-->
<!--                                    按地址搜索-->
<!--                                </el-button>-->
<!--                            </el-col>-->
<!--                        </er-row>-->
                        <el-row>
                            <el-col :span="24">
                                <!--<el-button type="primary" size="mini" @click="sear()">搜索</el-button>-->
                                <div style="display: none;width: 100%;height: 340px" id="map"></div>
                            </el-col>
                        </el-row>
                    </el-form>
                    <div slot="footer" class="dialog-footer">
                        <el-button @click="dialogFormVisible = false">取消</el-button>
                        <el-button type="primary" @click="handleAdd()">确定</el-button>
                    </div>
                </el-dialog>
            </div>
            <!-- 编辑标签弹层 -->
            <div class="add-form">
                <el-dialog title="编辑体检机构地址" :visible.sync="dialogFormVisible4Edit" width="80%">
                    <el-form ref="dataEditForm" :model="formData" :rules="rules" label-position="right"
                             label-width="100px">
                        <el-row>
                            <el-col :span="12">
                                <el-form-item label="体检机构名" prop="name">
                                    <el-input v-model="formData.name"/>
                                </el-form-item>
                            </el-col>
                            <el-col :span="12">
                                <el-form-item label="联系电话" prop="phoneNumber">
                                    <el-input v-model="formData.phoneNumber"/>
                                </el-form-item>
                            </el-col>
                        </el-row>
                        <el-row>
                            <el-col :span="24">
                                <el-form-item label="上传体检机构地址图片">
                                    <el-upload
                                            class="avatar-uploader"
                                            action="/address/upload.do"
                                            :auto-upload="autoUpload"
                                            name="imgFile"
                                            :show-file-list="false"
                                            :on-success="handleAvatarSuccess"
                                            :before-upload="beforeAvatarUpload">
                                        <img v-if="imageUrl" :src="imageUrl" class="avatar">
                                        <i v-else class="el-icon-plus avatar-uploader-icon"></i>
                                    </el-upload>
                                </el-form-item>
                            </el-col>
                        </el-row>
                        <el-row>
                            <el-col :span="20">
                                <el-form-item label="经纬度" prop="coordinate">
                                    <el-input v-model="formData.coordinate" id="lngAndLat2">
                                    </el-input>
                                </el-form-item>
                            </el-col>
                        </el-row>
                        <el-row>
                            <el-col :span="14">
                                <el-form-item label="详细地址">
                                    <el-input id="address2" v-model="formData.addressDetails"></el-input>
                                </el-form-item>
                            </el-col>

<!--                            <el-col :span="4">-->
<!--                                 <el-button type="primary" @click="setLocation()" round>-->
<!--                                     设置定位-->
<!--                                 </el-button>-->
<!--                                <el-button type="primary" @click="setLocation2()" icon="el-icon-location" round>位置定位-->
<!--                                </el-button>-->
<!--                            </el-col>-->

                            <el-col :span="4">
                                <el-button type="primary" icon="el-icon-location"
                                           @click="sear2()">
                                    按地址搜索
                                </el-button>
                            </el-col>
                        </el-row>
                        <!--<er-row>
                            <el-col :span="10">
                                <input name="address" value="" id="where" class="case_text" type="text">
                                <el-button type="primary" icon="el-icon-location" style="display: inline" @click="sear()">
                                    按地址搜索
                                </el-button>
                            </el-col>
                        </er-row>-->
                        <el-row>
                            <el-col :span="24">
                                <!--<el-button type="primary" size="mini" @click="sear()">搜索</el-button>-->
                                <div style="padding-left:150px;display: none;width: 650px;height: 400px" id="map2"></div>
                            </el-col>
                        </el-row>
                    </el-form>
                    <div slot="footer" class="dialog-footer">
                        <el-button @click="cancelEdit()">取消</el-button>
                        <el-button type="primary" @click="handleEdit()">确定</el-button>
                    </div>
                </el-dialog>
            </div>
        </div>
    </div>
</div>
</body>
<!-- 引入组件库 -->
<script type="text/javascript" src="../js/jquery.min.js"></script>
<script src="../js/vue.js"></script>
<script src="../plugins/elementui/index.js"></script>
<script src="../js/axios-0.18.0.js"></script>
<script type="text/javascript" src="http://api.map.baidu.com/api?v=2.0&ak=lP9BUGG19Ij8GrqzyYIf7j0BteUZN3fk"></script>
<script>

    var vue = new Vue({
        el: '#app',
        data: {
            autoUpload: true,//自动上传
            imageUrl: null,//模型数据，用于上传图片完成后图片预览
            pagination: {//分页相关属性
                currentPage: 1,
                pageSize: 10,
                total: 100,
                queryString: null,
            },
            longitude: null,
            latitude: null,
            is_empty: 0,
            dataList: [],//列表数据
            formData: {},//表单数据
            dialogFormVisible: false,//控制添加窗口显示/隐藏
            dialogFormVisible4Edit: false,//控制编辑窗口显示/隐藏
            rules: {//校验规则
                name: [{required: true, message: '体检机构名称为必填项', trigger: 'blur'}]
                // coordinate: [{required: true, message: '体检机构名称为必填项', trigger: 'blur'}]
            }
        },
        created() {
            this.findPage();
        },
        methods: {
            //文件上传成功后的钩子，response为服务端返回的值，file为当前上传的文件封装成的js对象
            handleAvatarSuccess(response, file) {
                //为模型数据imageUrl赋值，用于页面图片预览
                console.log("response  "+response)
                this.imageUrl =response.data;
                console.log("imgUrl  "+this.imageUrl)
                this.$message({
                    type: response.flag ? 'success' : 'error',
                    message: response.message
                });
                //设置模型数据（图片名称），后续提交ajax请求时会提交到后台最终保存到数据库
                this.formData.img = response.data;
            },
            //上传图片之前执行
            beforeAvatarUpload(file) {
                const isJPG = file.type === 'image/jpeg';
                const isLt2M = file.size / 1024 / 1024 < 2;
                if (!isJPG) {
                    this.$message.error('上传套餐图片只能是 JPG 格式!');
                }
                if (!isLt2M) {
                    this.$message.error('上传套餐图片大小不能超过 2MB!');
                }
                return isJPG && isLt2M;
            },

            //添加
            handleAdd() {
                //进行表单校验
                this.$refs['dataAddForm'].validate((valid) => {
                    if (valid) {
                        //发送ajax请求,将表单数据提交给后台进行处理
                        // this.formData.coordinate=$("#lngAndLat").val();
                        // this.formData.addressDetails=$("#address").val();
                        axios.post("/address/add.do", this.formData).then((resp) => {
                            if (resp.data.flag) {
                                //表示添加成功
                                this.$message.success(resp.data.message);
                            } else {
                                //表示添加失败
                                this.$message.error(resp.data.message);
                            }
                        }).finally(() => {
                            //无论添加操作是否成功,都执行分页查询操作
                            this.findPage();
                            //隐藏新增窗口
                            this.dialogFormVisible = false;
                        });
                    } else {
                        //表示校验失败
                        this.$message.error("数据校验失败,请检测您输入是否合法!")
                    }
                });
            },

            //分页查询
            findPage() {
                //分页参数
                var param = {
                    currentPage: this.pagination.currentPage,//页码
                    pageSize: this.pagination.pageSize,//每页显示的记录数
                    queryString: this.pagination.queryString//查询条件
                };
                //请求后台
                axios.post("/address/findPage.do", param).then((response) => {
                    //为模型数据赋值，基于VUE的双向绑定展示到页面
                    this.dataList = response.data.data.rows;
                    this.pagination.total = response.data.total;
                });
            },

            // 重置表单
            resetForm() {
                this.formData = {};
                //经纬度以及详细地址置空
                $("#lngAndLat").val('');
                $("#address").val('');
                $("#map").hide();//隐藏地图div
                this.imageUrl = null;
                if (this.$refs['dataAddForm'] !== undefined) {
                    this.$refs['dataAddForm'].clearValidate();
                }

            },

            // 弹出添加窗口
            handleCreate() {

                this.dialogFormVisible = true;//弹出新增体检机构地址信息窗口
                this.resetForm(); //重置表单
            },

            //切换页码
            handleCurrentChange(currentPage) {
                this.pagination.currentPage = currentPage;
                this.findPage();
            },

            // 弹出编辑窗口
            handleUpdate(row) {
                /*//alert(row.id)
                this.imageUrl = '';
                this.dialogFormVisible4Edit = true;
                axios.get("/address/findById.do?id=" + row.id).then((resp) => {
                    if (resp.data.flag) {
                        this.formData = resp.data.data;
                        this.imageUrl = 'http://qel4stjal.bkt.clouddn.com/' + resp.data.data.img;
                        imgurlchange = resp.data.data.img;
                        this.$message({
                            type: 'success',
                            message: resp.data.message
                        })
                    } else {
                        this.$message.error(resp.data.message);
                    }
                });
                if (this.$refs['dataEditForm'] !== undefined) {
                    this.$refs['dataEditForm'].clearValidate();
                }*/
                //弹出编辑窗口
                this.dialogFormVisible4Edit = true;
                //数据回显,row代表表格当前一行的数据,是一个address的json对象,
                this.formData = row;


                //图片的回显,指定七牛云的存储图片的url
                if (row.img != null) {
                    this.imageUrl =  row.img;
                } else {
                    this.imageUrl = null;
                }

                // 百度地图API功能
                //var map = new BMap.Map("map2");
                //map.centerAndZoom(new BMap.Point(116.331398, 39.897445), 11);
                //map.enableScrollWheelZoom(true);

                // 用经纬度设置地图中心点,获取表单数据经纬度的值并分割
                this.longitude = row.coordinate.split(",")[0];
                this.latitude = row.coordinate.split(",")[1];

            },

            //编辑检查套餐
            handleEdit() {
                this.$refs['dataEditForm'].validate((valid) => {
                    if (valid) {
                        //单独为经纬度以及详细地址赋值
                        this.formData.coordinate=$("#lngAndLat2").val();
                        this.formData.addressDetails=$("#address2").val();
                        //发送ajax请求,将表单数据提交给后台进行处理
                        axios.post("/address/edit.do",this.formData).then((resp) => {
                            if (resp.data.flag) {
                                //表示添加成功
                                this.$message.success(resp.data.message);
                            } else {
                                //表示添加失败
                                this.$message.error(resp.data.message);
                            }
                        }).finally(() => {
                            //无论添加操作是否成功,都执行分页查询操作
                            this.findPage();
                            //隐藏编辑窗口
                            this.dialogFormVisible4Edit = false;
                        });
                    } else {
                        //表示校验失败
                        this.$message.error("数据校验失败,请检出您输入是否合法!")
                    }
                });
            },

            //取消编辑检查套餐
            cancelEdit() {
                //隐藏编辑窗口
                this.dialogFormVisible4Edit = false;
                //将图片预览数据赋值,否则取消编辑后图片会预览失败
                //this.imageUrl=this.imgName;
                //重新进行体检预约机构的分页查询
                this.findPage();
            },

            //权限不足的提示
            showMessage(error) {
                if ("403" == (error.response.status)) {
                    //表示被禁止
                    vue.$message.error("无访问权限");
                } else {
                    vue.$message.error("未知错误")
                }
            },

            //删除
            handleDelete(row) { //row代表每一行的数据,是一个json对象
                this.$confirm('确定要删除' + row.name + '项这一行数据吗?', '提示', {
                    type: 'warning'
                }).then(() => {
                    var img = row.img;
                    //用户点击确认删除,发送ajax请求,将检查项id提交到后台进行处理
                    axios.post("/address/deleteById.do?id=" + row.id,img).then((resp) => {
                        if (resp.data.flag) {
                            //表示删除操作成功,进行提示
                            this.$message.success(resp.data.message);
                        } else {
                            //表示删除操作失败,进行提示
                            this.$message.error(resp.data.message);
                        }
                    }).catch((error) => {
                        //调用响应失败的函数
                        this.showMessage(error);
                    }).finally(() => {
                        //无论是否删除成功,都执行分页查询
                        this.findPage();
                    });
                }).catch(() => {
                    this.$message({
                        type: 'info',
                        message: '已取消删除'
                    });
                });
            },

            //设置定位
            setLocation() {
                //this.is_empty = 0;
                $("#map").show();//显示地图div
                var map = new BMap.Map("map");
                var point = new BMap.Point(116.331398,39.897445);
                map.centerAndZoom(point,12);

                //$("#map").load("setLocation.html");

                var map = new BMap.Map("map");//在指定的容器内创建地图实例
                //map.setDefaultCursor("crosshair");//设置地图默认的鼠标指针样式
                //map.enableScrollWheelZoom();//启用滚轮放大缩小，默认禁用。
                //var point = new BMap.Point(lng, lat);
                //map.centerAndZoom(point, 15);
                //map.addControl(new BMap.NavigationControl());
                //var marker = new BMap.Marker(point);        // 创建标注
                //this.map.addOverlay(marker);

                if (this.is_empty == 0) {
                    // var myCity = new BMap.LocalCity();
                    // myCity.get(iploac);
                    dingwei();
                }

                map.addEventListener("click", function (e) {//地图单击事件
                    var geocoder = new BMap.Geocoder();
                    var point = new BMap.Point(e.point.lng, e.point.lat);
                    geocoder.getLocation(point, function (geocoderResult, LocationOptions) {
                        map.clearOverlays()
                        //map.addControl(new BMap.NavigationControl());
                        //var marker = new BMap.Marker(point);        // 创建标注
                        //this.map.addOverlay(marker);
                        //定位成功
                        var address = geocoderResult.address;
                        $("#address").val(address);
                        //layer.msg('定位成功');
                        // $('#suggestId').val(geocoderResult.address);
                    });
                    $("#lngAndLat").val(e.point.lng + "," + e.point.lat);
                });


                function dingwei() {
                    var geolocation = new BMap.Geolocation();
                    geolocation.getCurrentPosition(function (r) {
                        if (this.getStatus() == BMAP_STATUS_SUCCESS) {
                            var mk = new BMap.Marker(r.point);
                            map.addOverlay(mk);
                            map.panTo(r.point);
                            //document.getElementById("lng").value = r.point.lng;
                            //document.getElementById("lat").value = r.point.lat;
                            var city_name = r.address.province + r.address.city;
                            //点击设置定位后就自动定位当前地址,并给经纬度和详细地址文本域赋值
                            $("#address").val(city_name);
                            //document.getElementById("where").value = city_name
                            $("#lngAndLat").val(r.point.lng + "," + r.point.lat);
                        } else {
                            console.log('获取失败');
                        }
                    });
                }
                return map;
            },

            //在文本框搜索指定地址，地图显示并定位
            sear() {
                //设置是否调用定位方法的标记为1
                this.is_empty = 1;
                //调用设置定位方法
                var map = this.setLocation();
                var map = new BMap.Map("map");
                var point = new BMap.Point(116.331398,39.897445);
                map.centerAndZoom(point,12);
                //var result = document.getElementById('where').value
                var result = $('#address').val();
                if (result.length == 0) {
                    var geolocation = new BMap.Geolocation();
                    geolocation.getCurrentPosition(function (r) {
                        if (this.getStatus() == BMAP_STATUS_SUCCESS) {
                            var mk = new BMap.Marker(r.point);
                            map.addOverlay(mk);
                            map.panTo(r.point);
                            //document.getElementById("lng").value = r.point.lng;
                            //document.getElementById("lat").value = r.point.lat;
                            var city_name = r.address.province + r.address.city;
                            //点击设置定位后就自定定位当前地址,并给经纬度和详细地址文本域赋值
                            $("#address").val( city_name);
                            //document.getElementById("where").value = city_name
                            $("#lngAndLat").val(r.point.lng + "," + r.point.lat);
                        } else {
                            console.log('获取失败');
                        }
                    });
                    return false;
                }
                var local = new BMap.LocalSearch(map, {
                    renderOptions: {map: map}
                });
                local.search(result);

                //根据输入的地址 逆解析 回显经纬度
                var point = new BMap.Point(116.331398, 39.897445);
                map.centerAndZoom(point, 12);
                // 创建地址解析器实例
                var myGeo = new BMap.Geocoder();
                // 将地址解析结果显示在地图上,并调整地图视野
                myGeo.getPoint(result, function (point) {
                    if (point) {
                        map.centerAndZoom(point, 16);
                        map.addOverlay(new BMap.Marker(point));
                        //给经纬度文本框赋值
                        $("#lngAndLat").val(point.lng + "," + point.lat);
                        vue.formData.coordinate = point.lng + "," + point.lat;
                    } else {
                        alert("您选择地址没有解析到结果!");
                    }
                }, "北京市");
            },

            //设置定位
            setLocation2() {
                //this.is_empty = 0;
                //$("#map").load("setLocation.html");
                $("#map2").show();//显示地图div
                lng = null;
                lat = null;
                var map = new BMap.Map("map2");//在指定的容器内创建地图实例
                //map.setDefaultCursor("crosshair");//设置地图默认的鼠标指针样式
                //map.enableScrollWheelZoom();//启用滚轮放大缩小，默认禁用。
                var point = new BMap.Point(lng, lat);
                map.centerAndZoom(point, 15);
                //map.addControl(new BMap.NavigationControl());
                //var marker = new BMap.Marker(point);        // 创建标注
                //this.map.addOverlay(marker);

                if (this.is_empty == 0) {
                    // var myCity = new BMap.LocalCity();
                    // myCity.get(iploac);
                    dingwei();
                }

                map.addEventListener("click", function (e) {//地图单击事件
                    var geocoder = new BMap.Geocoder();
                    var point = new BMap.Point(e.point.lng, e.point.lat);
                    geocoder.getLocation(point, function (geocoderResult, LocationOptions) {
                        map.clearOverlays()
                        map.addControl(new BMap.NavigationControl());
                        var marker = new BMap.Marker(point);        // 创建标注
                        //this.map.addOverlay(marker);
                        //定位成功
                        var address = geocoderResult.address;
                        $("#address2").val(address);
                        //document.getElementById("where").value = address;
                        //layer.msg('定位成功');
                        // $('#suggestId').val(geocoderResult.address);
                    });
                    $("#lngAndLat2").val(e.point.lng + "," + e.point.lat);
                    vue.formData.coordinate = $("#lngAndLat2").val(e.point.lng + "," + e.point.lat);
                });


                function dingwei() {
                    var geolocation = new BMap.Geolocation();
                    geolocation.getCurrentPosition(function (r) {
                        if (this.getStatus() == BMAP_STATUS_SUCCESS) {
                            var mk = new BMap.Marker(r.point);
                            map.addOverlay(mk);
                            map.panTo(r.point);
                            //document.getElementById("lng").value = r.point.lng;
                            //document.getElementById("lat").value = r.point.lat;
                            var city_name = r.address.province + r.address.city;
                            //点击设置定位后就自动定位当前地址,并给经纬度和详细地址文本域赋值
                            $("#address2").val(city_name);
                            //document.getElementById("where").value = city_name
                            $("#lngAndLat2").val(r.point.lng + "," + r.point.lat);
                            vue.formData.coordinate = $("#lngAndLat2").val(e.point.lng + "," + e.point.lat);
                        } else {
                            console.log('获取失败');
                        }
                    });
                }
                return map;
            },

            //在文本框搜索指定地址，地图显示并定位
            sear2() {
                //设置是否调用定位方法的标记为1
                this.is_empty = 1;
                //调用设置定位方法
                var map = this.setLocation2();
                /*var map = new BMap.Map("map");
                var point = new BMap.Point(116.331398,39.897445);
                map.centerAndZoom(point,12);*/
                //var result = document.getElementById('where').value
                var result = $('#address2').val();
                if (result.length == 0) {
                    var geolocation = new BMap.Geolocation();
                    geolocation.getCurrentPosition(function (r) {
                        if (this.getStatus() == BMAP_STATUS_SUCCESS) {
                            var mk = new BMap.Marker(r.point);
                            map.addOverlay(mk);
                            map.panTo(r.point);
                            //document.getElementById("lng").value = r.point.lng;
                            //document.getElementById("lat").value = r.point.lat;
                            var city_name = r.address.province + r.address.city;
                            //点击设置定位后就自定定位当前地址,并给经纬度和详细地址文本域赋值
                            $("#address2").val( city_name);
                            //document.getElementById("where").value = city_name
                            $("#lngAndLat2").val(r.point.lng + "," + r.point.lat);
                            vue.formData.coordinate = $("#lngAndLat2").val(e.point.lng + "," + e.point.lat);
                        } else {
                            console.log('获取失败');
                        }
                    });
                    return false;
                }
                var local = new BMap.LocalSearch(map, {
                    renderOptions: {map: map}
                });
                local.search(result);

                //根据输入的地址 逆解析 回显经纬度
                var point = new BMap.Point(116.331398, 39.897445);
                map.centerAndZoom(point, 12);
                // 创建地址解析器实例
                var myGeo = new BMap.Geocoder();
                // 将地址解析结果显示在地图上,并调整地图视野
                myGeo.getPoint(result, function (point) {
                    if (point) {
                        map.centerAndZoom(point, 16);
                        map.addOverlay(new BMap.Marker(point));
                        //给经纬度文本框赋值
                        $("#lngAndLat2").val(point.lng + "," + point.lat);
                        vue.formData.coordinate = $("#lngAndLat2").val(e.point.lng + "," + e.point.lat);
                    } else {
                        alert("您选择地址没有解析到结果!");
                    }
                }, "北京市");
            }
        },
        //在数据更新的时候,调用根据经纬度定位的方法
        updated(){
            var map = new BMap.Map("map2");
            map.centerAndZoom(new BMap.Point(this.longitude, this.latitude), 11);
            //map.enableScrollWheelZoom(true); //设置鼠标缩放
            //alert(longitude);
            //alert(JSON.stringify(row));
            //alert(latitude);
            if (this.longitude != "" && this.latitude != "") {
                map.clearOverlays();
                var new_point = new BMap.Point(this.longitude, this.latitude);
                var marker = new BMap.Marker(new_point);  // 创建标注
                map.addOverlay(marker);              // 将标注添加到地图中
                map.panTo(new_point);
            }
            //显示map的div
            $("#map2").show();

            //地图单击事件
            map.addEventListener("click", function (e) {//地图单击事件
                var geocoder = new BMap.Geocoder();
                var point = new BMap.Point(e.point.lng, e.point.lat);
                geocoder.getLocation(point, function (geocoderResult, LocationOptions) {
                    map.clearOverlays()
                    map.addControl(new BMap.NavigationControl());
                    var marker = new BMap.Marker(point);        // 创建标注
                    //this.map.addOverlay(marker);
                    //定位成功
                    var address = geocoderResult.address;
                    $("#address2").val(address);
                    //document.getElementById("where").value = address;
                    //layer.msg('定位成功');
                    // $('#suggestId').val(geocoderResult.address);
                });
                $("#lngAndLat2").val(e.point.lng + "," + e.point.lat);
                vue.formData.coordinate = $("#lngAndLat2").val(e.point.lng + "," + e.point.lat);
            });
        }
    })
</script>
</html>
